/**
 * Copyright 2006 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.ocean.main.fields;

import java.util.Date;
import java.util.Map;

import org.apache.lucene.document.Fieldable;
import org.apache.ocean.main.IndexSchema;

public class LongFieldType extends FieldType {
  public LongFieldType() {
    typeName = "long";
  }
  
  protected void init(IndexSchema schema, Map<String,String> args) {  
  }
  
  public Class getType() {
  	return Long.class;
  }
  
  public String objectToExternal(Object object) {
  	return object.toString();
  }
  
  public String objectToIndexed(Object object) {
  	Long value = (Long)object;
  	return toInternal(value.toString());
  }
  
  public Object stringToObject(String string) {
  	return new Long(string);
  }
  
  public byte[] createPayloadBuffer() {
  	return new byte[8];
  }
  
  public byte[] objectToBytes(Object object) {
  	return NumberUtils.encode((Long)object);
  }
  
  public Object bytesToObject(byte[] bytes) {
  	return new Long(NumberUtils.decode(bytes));
  }
  
  public String toInternal(String val) {
    return NumberUtils.long2sortableStr(val);
  }

  public String indexedToReadable(String indexedForm) {
    return NumberUtils.sortableStr2long(indexedForm);
  }

  public String toExternal(Fieldable f) {
    return indexedToReadable(f.stringValue());
  }
}

